//
//  CustomTableViewCell.m
//  e-Learning
//
//  Created by rimi on 16/6/21.
//  Copyright © 2016年 YJ. All rights reserved.
//

#import "CustomTableViewCell.h"
@interface CustomTableViewCell()
@property (nonatomic,strong) UIView *lineVu;
@end

@implementation CustomTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //自身总高度Screen_Height/9*7/3
        [self.contentView addSubview:self.imageVu];
        [self.contentView addSubview:self.name];
        [self.contentView addSubview:self.introduce];
        [self.contentView addSubview:self.questions];
        [self.contentView addSubview:self.lesson];
        [self.contentView addSubview:self.answer];
        
        [self.contentView addSubview:self.lineVu];
    }
    return self;
}


- (UIImageView *)imageVu{
    if (!_imageVu) {
        _imageVu = [[UIImageView alloc] initWithFrame:CGRectMake(Screen_Height/9*7/3*0.08, Screen_Height/9*7/3*0.1, Screen_Width/8, Screen_Height/9*7/3*0.8)];
    }
    return _imageVu;
}

- (UILabel *)name{
    if (!_name) {
        _name = [[UILabel alloc] initWithFrame:CGRectMake(Screen_Height/9*7/3*0.15+Screen_Height/9*7/3*0.08+Screen_Width/8, Screen_Height/9*7/3*0.11, Screen_Width/8, Screen_Height/9*7/3*0.2)];
    }
    _name.font = [UIFont boldSystemFontOfSize:24];
    return _name;
}

- (UILabel *)introduce{
    if (!_introduce) {
        _introduce = [[UILabel alloc] initWithFrame:CGRectMake(Screen_Height/9*7/3*0.15+Screen_Height/9*7/3*0.08+Screen_Width/8, Screen_Height/9*7/3*0.11+Screen_Height/9*7/3*0.2, Screen_Width-Screen_Height/9*7/3*0.15-Screen_Height/9*7/3*0.08-Screen_Width/8-Screen_Height/9*7/3*0.15, Screen_Height/9*7/3*0.8/3*1.5)];
        _introduce.numberOfLines = 0;
        _introduce.font = [UIFont systemFontOfSize:20];
    }
    return _introduce;
}

- (CustomBtn *)questions{
    if (!_questions) {
        _questions = [[CustomBtn alloc] initWithFrame:CGRectMake(Screen_Width/2, Screen_Height/9*7/3*0.11+Screen_Height/9*7/3*0.2+Screen_Height/9*7/3*0.8/3*1.5, Screen_Width/2/10*3, Screen_Height/9*7/3*0.8/3/3*2) index:1];
        _questions.layer.cornerRadius = Screen_Height/9*7/3*0.8/3/3*2/2;
        _questions.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _questions.layer.borderWidth = 1;
        _questions.titleLabel.font = [UIFont boldSystemFontOfSize:20];
//        [_questions setBackgroundImage:[UIImage imageNamed:@"btn_bg_normal.png"] forState:UIControlStateNormal];
//        [_questions setBackgroundImage:[UIImage imageNamed:@"btn_bg_select.png"] forState:UIControlStateHighlighted];
        [_questions setTitle:@"向讲师提问" forState:UIControlStateNormal];
        [_questions setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_questions addTarget:self action:@selector(tapBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _questions;
}

- (CustomBtn *)lesson{
    if (!_lesson) {
        _lesson = [[CustomBtn alloc] initWithFrame:CGRectMake(Screen_Width/2+Screen_Width/2/10*3+Screen_Width/2/10*0.2, Screen_Height/9*7/3*0.11+Screen_Height/9*7/3*0.2+Screen_Height/9*7/3*0.8/3*1.5, Screen_Width/2/10*3, Screen_Height/9*7/3*0.8/3/3*2) index:2];
        _lesson.layer.cornerRadius = Screen_Height/9*7/3*0.8/3/3*2/2;
        _lesson.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _lesson.layer.borderWidth = 1;
        _lesson.titleLabel.font = [UIFont boldSystemFontOfSize:20];
//        [_lesson setBackgroundImage:[UIImage imageNamed:@"btn_bg_normal.png"] forState:UIControlStateNormal];
//        [_lesson setBackgroundImage:[UIImage imageNamed:@"btn_bg_select.png"] forState:UIControlStateHighlighted];
        [_lesson setTitle:@"他的课程" forState:UIControlStateNormal];
        [_lesson setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_lesson addTarget:self action:@selector(tapBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _lesson;
}

- (CustomBtn *)answer{
    if (!_answer) {
        _answer = [[CustomBtn alloc] initWithFrame:CGRectMake(Screen_Width/2+Screen_Width/2/10*3*2+Screen_Width/2/10*0.2*2, Screen_Height/9*7/3*0.11+Screen_Height/9*7/3*0.2+Screen_Height/9*7/3*0.8/3*1.5, Screen_Width/2/10*3, Screen_Height/9*7/3*0.8/3/3*2) index:3];
        _answer.layer.cornerRadius = Screen_Height/9*7/3*0.8/3/3*2/2;
        _answer.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _answer.layer.borderWidth = 1;
//        [_answer setBackgroundImage:[UIImage imageNamed:@"btn_bg_normal.png"] forState:UIControlStateNormal];
//        [_answer setBackgroundImage:[UIImage imageNamed:@"btn_bg_select.png"] forState:UIControlStateHighlighted];
        _answer.titleLabel.font = [UIFont boldSystemFontOfSize:20];
        [_answer setTitle:@"老师答疑" forState:UIControlStateNormal];
        [_answer setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_answer addTarget:self action:@selector(tapBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _answer;
}

- (UIView *)lineVu{
    if (!_lineVu){
        _lineVu = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_Height/9*7/3-1, Screen_Width, 1)];
        CAGradientLayer *gradient1 = [[CAGradientLayer alloc] init];
        gradient1.frame = CGRectMake(0, 0, Screen_Width/2, 1);
        gradient1.startPoint = CGPointMake(0.2, 0.5);
        gradient1.endPoint = CGPointMake(0.5, 0.5);
        gradient1.colors = [NSArray arrayWithObjects:(id)[[UIColor clearColor] colorWithAlphaComponent:0].CGColor,(id)[[UIColor lightGrayColor] colorWithAlphaComponent:0.5].CGColor, nil];
        CAGradientLayer *gradient2 = [[CAGradientLayer alloc] init];
        gradient2.frame = CGRectMake(Screen_Width/2, 0, Screen_Width/2, 1);
        gradient2.startPoint = CGPointMake(0.5, 0.5);
        gradient2.endPoint = CGPointMake(0.8, 0.5);
        gradient2.colors = [NSArray arrayWithObjects:(id)[[UIColor lightGrayColor] colorWithAlphaComponent:0.5].CGColor,(id)[[UIColor clearColor] colorWithAlphaComponent:0].CGColor, nil];
        [_lineVu.layer addSublayer:gradient1];
        [_lineVu.layer addSublayer:gradient2];
    }
    return _lineVu;
}


- (void)tapBtn:(CustomBtn *)sender{
    if (_delegate && [_delegate respondsToSelector:@selector(tapButtonID:btnTitleIndex:)]) {
        [_delegate tapButtonID:self.teacherID btnTitleIndex:sender.index];
    }
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
